package ch.zhaw.swp1.view.component;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * Generic class to define badge 
 * @author Daniel Tiefenauer
 */
public abstract class Badge extends JPanel {

	/**
	 * Default version
	 */
	private static final long serialVersionUID = 1L;
	
	protected JLabel badgeLabel = new JLabel();
	protected JButton badgeButton = new JButton(new ImageIcon("images/icon_close.jpg"));

	/************************************************************************************/
	// Constructors
	/*----------------------------------------------------------------------------------*/
	/**
	 * Default constructor with empty badge label
	 */
	public Badge(){
		this("");
	}
	
	/**
	 * Overloaded constructor with badge text
	 * @param text the badge label to be shown
	 */
	public Badge(String text){
		init();
		layoutComponents();
		badgeLabel.setText(text);	
	}
	
	/************************************************************************************/
	// Methods
	/*----------------------------------------------------------------------------------*/
	/**
	 * Initialize
	 */
	private void init(){
		// General
		setLayout(new FlowLayout());
		setPreferredSize(new Dimension(300, 35));
		setMaximumSize(getPreferredSize());
		setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
		
		// Badge label
		badgeLabel.setAlignmentX(LEFT_ALIGNMENT);
		badgeLabel.setAlignmentY(CENTER_ALIGNMENT);
		badgeLabel.setPreferredSize(new Dimension(270, 30));
		
		// Badge Button
		badgeButton.setMargin(new Insets(0,0,0,0));
		badgeButton.setAlignmentX(RIGHT_ALIGNMENT);
		badgeButton.setPreferredSize(new Dimension(16,16));
		
	}
	
	/**
	 * Lay out components on screen
	 */
	private void layoutComponents(){
		add(badgeLabel);
		add(badgeButton);
	}
	
	/***************************************************************************************/
	// Getter/Setter
	/*----------------------------------------------------------------------------------*/
	public JButton getBadgeButton(){
		return badgeButton;
	}

	
}
